<?php if(!defined('BASEPATH')) exit('No direct script allowed');

class mdl_berita_acara extends CI_Model{
	
	function __construct()
	{
		parent::__construct();
	}
	
	function getSudahBayar($bulan=null,$tahun=null, $parawaba=null)
	{
		$query = "select a.id, a.nama,			(SELECT sum(kredit) from mcm c where c.parawaba = a.id and c.status_posting = 'posting' and MONTH(c.tanggal) <= $bulan and YEAR(c.tanggal) = $tahun)as sudah_bayar			from master_parawaba a 			where a.id = $parawaba			"; 		       	        	$hasil =  $this->db->query($query);        					  				  return $hasil->result_array();
	}
	function cek($tahun=null, $parawaba=null)	{		$query = "select * from berita_acara where tahun = $tahun and parawaba = $parawaba"; 		       	        	$hasil =  $this->db->query($query);        					  				  return $hasil->result_array();	}
	function getItemById($id)
	{
		$this->db->flush_cache();
		$this->db->where('id', $id);
		return $this->db->get('master_parawaba');
	}

	function insert($data)
	{
		$this->db->flush_cache();
		$this->db->insert('berita_acara', $data);
	}
	
	function update($id, $data)
	{
		$this->db->flush_cache();
		$this->db->where('id_barang', $id);
		$this->db->update('barang', $data);
	}
	
	function delete($id)
	{
		$this->db->flush_cache();
		$this->db->delete('barang', array('id_barang' => $id));
	}
	
}
